package ewms.controller;

import java.util.List;
import java.util.Arrays;

import ewms.bo.EwmsWasteDeclareAddBo;
import ewms.bo.EwmsWasteDeclareEditBo;
import ewms.bo.EwmsWasteDeclareQueryBo;
import ewms.common.core.page.TableDataInfo;
import ewms.service.IEwmsWasteDeclareService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import ewms.common.annotation.RepeatSubmit;
import ewms.common.annotation.Log;
import ewms.common.core.controller.BaseController;
import ewms.common.core.domain.AjaxResult;
import ewms.common.enums.BusinessType;
import ewms.vo.EwmsWasteDeclareVo;
import ewms.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 危废申报Controller
 *
 * @author zhaoxiaochun
 * @date 2022-01-12
 */
@Api(value = "危废申报控制器", tags = {"危废申报管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/business/wasteDeclare")
public class EwmsWasteDeclareController extends BaseController {

    private final IEwmsWasteDeclareService iEwmsWasteDeclareService;

    /**
     * 查询危废申报列表
	 * @return
	 */
    @ApiOperation("查询危废申报列表")
    @PreAuthorize("@ss.hasPermi('business:wasteDeclare:list')")
    @GetMapping("/list")
    public TableDataInfo<EwmsWasteDeclareVo> list(@Validated EwmsWasteDeclareQueryBo bo) {
        return iEwmsWasteDeclareService.selectPageList(bo);
    }


    /**
     * 导出危废申报列表
     */
    @ApiOperation("导出危废申报列表")
    @PreAuthorize("@ss.hasPermi('business:wasteDeclare:export')")
    @Log(title = "危废申报", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EwmsWasteDeclareVo> export(@Validated EwmsWasteDeclareQueryBo bo) {
        List<EwmsWasteDeclareVo> list = iEwmsWasteDeclareService.selectList(bo);
        ExcelUtil<EwmsWasteDeclareVo> util = new ExcelUtil<EwmsWasteDeclareVo>(EwmsWasteDeclareVo.class);
        return util.exportExcel(list, "危废申报");
    }

    /**
     * 获取危废申报详细信息
     */
    @ApiOperation("获取危废申报详细信息")
    @PreAuthorize("@ss.hasPermi('business:wasteDeclare:query')")
    @GetMapping("/{wasteDeclareId}")
    public AjaxResult<EwmsWasteDeclareVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("wasteDeclareId") Long wasteDeclareId) {
        return AjaxResult.success(iEwmsWasteDeclareService.queryById(wasteDeclareId));
    }

    /**
     * 新增危废申报
     */
    @ApiOperation("新增危废申报")
    @PreAuthorize("@ss.hasPermi('business:wasteDeclare:add')")
    @Log(title = "危废申报", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody EwmsWasteDeclareAddBo bo) {
        return toAjax(iEwmsWasteDeclareService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改危废申报
     */
    @ApiOperation("修改危废申报")
    @PreAuthorize("@ss.hasPermi('business:wasteDeclare:edit')")
    @Log(title = "危废申报", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody EwmsWasteDeclareEditBo bo) {
        return toAjax(iEwmsWasteDeclareService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除危废申报
     */
    @ApiOperation("删除危废申报")
    @PreAuthorize("@ss.hasPermi('business:wasteDeclare:remove')")
    @Log(title = "危废申报" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{wasteDeclareIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] wasteDeclareIds) {
        return toAjax(iEwmsWasteDeclareService.deleteWithValidByIds(Arrays.asList(wasteDeclareIds), true) ? 1 : 0);
    }
}
